//
//  DetailActivityViewController.m
//  豆瓣HW
//
//  Created by dllo on 15/11/26.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DetailActivityViewController.h"
#import "DetailActivityView.h"
#import "LoginViewController.h"
#import "Activity.h"

@interface DetailActivityViewController ()

@end

@implementation DetailActivityViewController

- (void)dealloc
{
    [_act release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    
    self.navigationItem.title = self.act.title;
    
    UIImage *leftImage = [UIImage imageNamed:@"btn_nav_back@2x.png"];
    leftImage = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)];
    
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_share@2x.png"];
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStyleDone target:self action:@selector(barAction:)];
    
    
    DetailActivityView *detailV = [[DetailActivityView alloc] initWithFrame:self.view.frame];
    detailV.labelTitle.text = self.act.title;
    NSRange range = {5, 11};
    NSString *time = [self.act.begin_time substringWithRange:range];
    NSString *time1 = [self.act.end_time substringWithRange:range];
    NSString *time2 = [time stringByAppendingString:@" -- "];
    NSString *time3 = [time2 stringByAppendingString:time1];
    detailV.labelTime.text = time3;
    NSString *owner_name = [self.act.owner objectForKey:@"name"];
    detailV.labelPerson.text = owner_name;
    detailV.labelStyleName.text = self.act.category_name;
    detailV.labelPosition.text = self.act.address;
    detailV.lableActivityIntroduceDate.text = self.act.content;
    detailV.imageV.image = self.act.finalImage;
    
    [self.view addSubview:detailV];
    [detailV release];
}

- (void)barAction:(UIBarButtonItem *)sender
{
    if (sender == self.navigationItem.leftBarButtonItem) {
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginVC animated:YES];
        [loginVC release];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
